package com.huatai.datadevelop.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.huatai.datadevelop.entity.SysDocEntity;
import com.huatai.datadevelop.mapper.SysDocDao;
import com.huatai.datadevelop.utils.PageUtils;
import com.huatai.datadevelop.utils.Query;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * @Author zhangbenting
 * @Description TODO
 * @Date 2023/9/19 18:38
 * @Version 1.0
 */
@Service
public class DocService extends ServiceImpl<SysDocDao, SysDocEntity> {

	/**
	 * 保存或更新
	 * @param entity
	 * @return
	 */
	public boolean saveOrUpdateEntity(SysDocEntity entity){
		return this.saveOrUpdate(entity);
	}

	/**
	 * 获取单个
	 * @param sysDocId
	 * @return
	 */
	public SysDocEntity getDosById(Integer sysDocId) {
		SysDocEntity sysDoc = this.getById(sysDocId);
		return sysDoc;
	}

	/**
	 * 分页获取数据
	 * @param params
	 * @return
	 */
	public PageUtils queryPage(Map<String, Object> params) {
		String name = (String) params.get("docName");
		IPage<SysDocEntity> page = this.page(
			new Query<SysDocEntity>().getPage(params),
			new QueryWrapper<SysDocEntity>().like(StringUtils.isNotBlank(name), "doc_name", name)
		);
		return new PageUtils(page);
	}
}
